<template>
  <div class="item-lists">
    <h3 class="title">推荐商品</h3>
    <div class="item" v-for="item in items" @click="enterDetail(item.id)" :key="item.id">
      <van-card :price="item.minPrice" :title="item.name" :thumb="item.pic">
        <template #footer>
          <van-icon
            class-prefix="icon"
            size="22"
            color="#e93323"
            name="gouwuchetianjia"
            @click.stop="addCart(item.id)"
          />
        </template>
      </van-card>
    </div>
  </div>
</template>

<script setup lang="ts">
import { useRouter } from "vue-router";
defineProps<{
  items: any[];
}>();
const emit = defineEmits<{
  (e: "addCart", id: number): void;
}>();
const router = useRouter();
const enterDetail = (id: number) => {
  router.push({
    path: "/detail",
    query: {
      id,
    },
  });
};

const addCart = (goodsId: number) => {
  emit("addCart", goodsId);
};
</script>

<style scoped lang="scss">
.item-lists {
  .title {
    line-height: 40px;
    text-align: center;
    font-size: 18px;
  }
  .van-card {
    background-color: #fff;
  }
}
</style>
